Ext.define('PJ.view.messagemanagement.ReadPeopleList', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.readPeopleList'],
    requires: ['AM.default.DefaultSearchForm', 
               'AM.default.DateTime', 
               'AM.default.DefaultDateField'
               ],
   selModel: {
       selType: '',
       checkOnly: true
   },
    initComponent: function(){
    	var me = this;
        me.columns = [/*{
    		header: '登录号',
    		dataIndex: 'loginId',
    		flex: 1,
            minWidth: 120,
    		renderer: function(value, meta, record){
    			meta.tdAttr = "data-qtip='" + value + "' classId=" + record.get("classId");
    			return value;
    		}
    	}, */{
    		header: '接收人',
    		dataIndex: 'userName',
    		flex: 1,
    		minWidth: 120
    	}, {
            header: '回复时间',
            dataIndex: 'replyTime',
            width:120,
    		renderer: function(value, metaData, record){
    			metaData.tdAttr = 'data-qtip="' + value + '"';
    			return value;
    		}
        }, {
            header: '接收时间',
            dataIndex: 'receiveTime',
            width:120,
    		renderer: function(value, metaData, record){
    			metaData.tdAttr = 'data-qtip="' + value + '"';
    			return value;
    		}
        }, {
            header: '状态',
            dataIndex: 'readState',
            width:50,
    		renderer: function(value, metaData, record){
    			metaData.tdAttr = 'data-qtip="' + value + '"';
    			if(value==1){
    				return "<span style='color:blue'>已读</span>"
    			}else if(value==2){
    				return "<span style='color:red'>未读</span>"
    			}
    		}
        }/*,{
            header: '角色',
            dataIndex: 'roleName',
            width: 120 
        }*/, {
            header: '回复',
            menuDisabled: true,
            sortable: false,
            resizable: false,
            hideable: false,
            xtype: 'actioncolumn',
            width: 75,
            items: [{
            	tooltip: '回复',
            	getClass: function(v, meta, rec){
            		meta.style = "cursor: pointer;";
            		return 'templateIco';
        		},
                handler: function(grid, rowIndex, colIndex, item, eve, record){
                	var userId = record.get("userId");
                	var newsUserLink = record.get("newsUserLink");
                	var userName = record.get("userName");
                	var newsId = me.up("window").newsId;
    				var win = Ext.create("PJ.view.messagemanagement.ReplyEdit", {
            			title: "回复内容",
            			text:"发送通知",
            			userId:userId,
            			newsUserLink:newsUserLink,
            			newsId:newsId,
            			grid:grid
            		}).show();
    				var actionName = "load";
    				if(gj_onlineLearning_constant.loadType == "jsonp"){
    					actionName = "loadJsonp";
    				}
    				win.down("form").getForm().doAction(actionName,{
    					url:grid.getStore().preUpdateUrl,
    					params:{
    						userId:userId,
                			newsId:newsId
    					},
    					success:function(f,action){
    						var data = action.response.responseText;
    	        			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
//    	        			var newsUserLink = json.data.newsUserLink;
    	        			var form = win.down('form');	 
    	        			var baseForm = form.getForm();
    	        			baseForm.findField("receiveUserNames").setValue(userName);
    	        			var newsType = json.data.newsType.dataName;
    	        			baseForm.findField("newsCode").setValue(newsType);
    	        			if(json.data.newsTypeCode=="xxlx_pxb"){
    	        				baseForm.findField("specialName").setVisible(true);
    	        				baseForm.findField("specialName").setValue(json.data.className);
    	        				win.setHeight(570);
    	        			}else{
    	        				baseForm.findField("specialName").setVisible(false);
    	        				win.setHeight(540);
    	        			}
    	        			var list = win.down("restoredMessageList");
    	        			list.newsUserLink = newsUserLink;
    	        			var store = list.store;
    	                    var params = store.proxy.extraParams;
    	                    var newParams = {
    	                    		searchNewsId: newsId,
    	                    		searchNewsUserLink: newsUserLink
    	                    };
    	                    Ext.apply(params, newParams);
    	                    store.isLoad = true;
    	                    store.load();
    					}
    				});
                }
            },{
            	getClass: function(v, meta, rec){
            		if(rec.get("isNewReply")==1){
            			return 'newSignIco';
            		}
        		},
            }]
        }];
        me.store = Ext.create('PJ.'+ prototype +'.messagemanagement.ReadPeopleList', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
        me.callParent(arguments);
    },
    listeners: {
    	viewready: function(){
    		var me = this;
    		me.addDocked([{
    			dock: 'top',
    			xtype: "searchform",
    			columnCount: 2,
    			fieldDefaults: {
    				labelAlign: 'right',
    				labelWidth: 70
    			},
    			items: [/*{
    				xtype: "textfield",
    				fieldLabel: '登录号',
    				name: "searchLoginId",
    				maxLength: "50",
    				emptyText: "请输入登录号"
    			},*/{
    				xtype: "textfield",
    				fieldLabel: '接收人',
    				name: "searchUserName",
    				maxLength: "50",
    				emptyText: "请输入接收人"
    			},{
					xtype: "combo",
					fieldLabel: '状态',
					name: "searchReadState",
					store: Ext.create("Ext.data.ArrayStore", {
						fields: ['value', 'text'],
						data: [[1, '已读'],[2,'未读']]
					}),
					valueField: 'value',
					displayField: 'text',
					editable: false,
					emptyText: "请选择"
				}/*,{
    				xtype: "textfield",
    				fieldLabel: '角色',
    				name: "searchRoleCode",
    				maxLength: "50",
    				emptyText: "请输入角色"
    			}*/],
                onResetClick: function(button){
                    var form = button.up('form');
                    var gridPanel = form.grid;
                    var newParams = {
                        searchNewsId:me.up("window").newsId
                    };
                    gridPanel.getStore().proxy.extraParams = {};
                    var params = gridPanel.getStore().proxy.extraParams;
                    Ext.apply(params, newParams);
                    form.getForm().reset();
                },
    			grid: this
    		}]);
            var store = this.store;
            var params = store.proxy.extraParams;
            var newParams = {
            	searchNewsId:me.up("window").newsId
            };
            Ext.apply(params, newParams);
            store.isLoad = true;
            store.load();
    		// 触发权限过滤事件
    		this.fireEvent("permission", this);
    	}
    }
});
